<template>
  <div class="login-container">
    <van-nav-bar title="登录" />
    
    <div class="header">
      <h2>欢迎回来</h2>
      <p>登录您的账号以继续学习</p>
    </div>
    
    <div class="form-container">
      <van-form @submit="onSubmit">
        <van-cell-group inset>
          <van-field
            v-model="username"
            name="username"
            placeholder="请输入用户名"
            :rules="[{ required: true, message: '请输入用户名' }]"
          >
            <template #left-icon>
              <van-icon name="contact" />
            </template>
          </van-field>
          
          <van-field
            v-model="password"
            type="password"
            name="password"
            placeholder="请输入密码"
            :rules="[{ required: true, message: '请输入密码' }]"
          >
            <template #left-icon>
              <van-icon name="lock" />
            </template>
          </van-field>
        </van-cell-group>

        <div class="submit-btn">
          <van-button round block type="primary" native-type="submit" size="large">
            登录
          </van-button>
        </div>
      </van-form>

      <div class="helper-links">
        <router-link to="/reset-password" class="forgot-password">忘记密码？</router-link>
        <router-link to="/register" class="register-link">注册账号</router-link>
      </div>

      <div class="other-login">
        <div class="divider">
          <span>其他登录方式</span>
        </div>
        
        <div class="login-methods">
          <div class="method" @click="loginWithWeChat">
            <van-icon name="wechat" size="28" class="method-icon wechat" />
            <span>微信登录</span>
          </div>
          <div class="method" @click="loginWithPhone">
            <van-icon name="phone-o" size="28" class="method-icon phone" />
            <span>手机号登录</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { showSuccessToast } from 'vant'

const router = useRouter()
const username = ref('')
const password = ref('')

const onSubmit = (values) => {
  console.log('submit', values)
  showSuccessToast('登录成功')
  router.push('/')
}

const loginWithWeChat = () => {
  showSuccessToast('微信登录功能开发中')
}

const loginWithPhone = () => {
  router.push('/login-phone')
}
</script>

<style lang="scss" scoped>
.login-container {
  min-height: 100vh;
  background: #f7f8fa;
  padding-bottom: 40px;

  .header {
    background: linear-gradient(135deg, #1989fa, #39b9f9);
    padding: 48px 24px 64px;
    color: white;
    text-align: center;
    border-radius: 0 0 24px 24px;

    h2 {
      font-size: 28px;
      margin: 0 0 12px;
      font-weight: 600;
    }

    p {
      font-size: 16px;
      margin: 0;
      opacity: 0.9;
    }
  }

  .form-container {
    margin-top: -32px;
    padding: 0 16px;

    :deep(.van-cell-group--inset) {
      margin: 0;
      border-radius: 12px;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
    }

    :deep(.van-field__left-icon) {
      margin-right: 8px;
      color: #666;
    }
  }

  .submit-btn {
    margin-top: 24px;
    padding: 0 16px;
  }

  .helper-links {
    display: flex;
    justify-content: space-between;
    margin-top: 16px;
    padding: 0 16px;

    a {
      color: #1989fa;
      text-decoration: none;
      font-size: 14px;
    }
  }

  .other-login {
    margin-top: 48px;
    padding: 0 16px;

    .divider {
      position: relative;
      text-align: center;
      margin-bottom: 24px;

      &::before,
      &::after {
        content: '';
        position: absolute;
        top: 50%;
        width: calc(50% - 80px);
        height: 1px;
        background: #eee;
      }

      &::before {
        left: 0;
      }

      &::after {
        right: 0;
      }

      span {
        display: inline-block;
        padding: 0 16px;
        color: #999;
        font-size: 14px;
        background: #f7f8fa;
      }
    }

    .login-methods {
      display: flex;
      justify-content: center;
      gap: 48px;

      .method {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;
        cursor: pointer;

        .method-icon {
          &.wechat {
            color: #07c160;
          }

          &.phone {
            color: #1989fa;
          }
        }

        span {
          font-size: 12px;
          color: #666;
        }
      }
    }
  }
}
</style>
